package com.burgeon.backend.SHOP.service.Impl;

import com.burgeon.backend.SHOP.entity.Seckill;
import com.burgeon.backend.SHOP.mappers.GoodsMapper;
import com.burgeon.backend.SHOP.mappers.SeckillMapper;
import com.burgeon.backend.SHOP.service.SeckillService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class SeckillServiceImpl implements SeckillService {
    @Autowired
    private SeckillMapper seckillMapper;
    @Autowired
    private GoodsMapper goodsMapper;

    @Override
    public List<Seckill> getDatanew(Integer start, String token) {
        start = start*10;

        List<Seckill> data = seckillMapper.getDatanew(start,token);
        for (Seckill seckill : data){
            seckill.setGoods(goodsMapper.getGoodsById(seckill.getGid()));
        }

        return data;
    }

    @Override
    public List<Seckill> getData(String token) {

        List<Seckill> data = seckillMapper.getData(token);
        for (Seckill seckill : data){
            seckill.setGoods(goodsMapper.getGoodsById(seckill.getGid()));
        }

        return data;
    }

    @Override
    public List<Seckill> findData(Integer start,String message, String token) {
        start = start*10;

        List<Seckill> data = seckillMapper.findSeckillData(start,message, token);

        for (Seckill seckill : data){
            seckill.setGoods(goodsMapper.getGoodsById(seckill.getGid()));
        }
        return data;
    }
}
